import Vue from 'vue'
import Vuex from 'vuex'
import createVuexAlong from 'vuex-along'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
     // 存储token
     Authorization: localStorage.getItem('Authorization') ? localStorage.getItem('Authorization') : '',
     Name:'',
     isAdmin:'',
     Avatar:'',
     total:0,
     visitTotal:0,
     canpost:new Date().getTime(),
  },
  mutations: {
    // 修改token，并将token存入localStorage
    changeLogin (state, user) {
      state.Authorization = user.Authorization;
      localStorage.setItem('Authorization', user.Authorization);
    },
    changeName(state, user){
      state.Name = user.Name;
    },
    changeAdmin(state, user){
      state.isAdmin = user.isAdmin;
    },
    changeAvatar(state, user){
      state.Avatar = user.Avatar;
    },
    changeTotal(state, user){
      state.total = user.total;
    },
    changevisitTotal(state, user){
      state.visitTotal = user.visitTotal;
    },
    changeCanPost(state, user){
      state.canpost = user.canpost;
    },
  },
  actions: {
  },
  modules: {
  },
  plugins: [createVuexAlong()]//vuex持久化
})
